//
//  TZLoginViewController.m
//  wangYiLottery
//
//  Created by mac on 16/2/20.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZLoginViewController.h"
#import "TZSMSLoginController.h"
#import "TZNewUserController.h"
#import "TZNewPasswordController.h"
#import "TZSuccessLoginController.h"
@interface TZLoginViewController ()
@property (nonatomic, strong) UIImageView *logoImageView;
@property (nonatomic, strong) UIView *userNameView;
@property (nonatomic, strong) UIView *passWordView;
@property (nonatomic, strong) UIButton *smsButton;
@property (nonatomic, strong) UIButton *loginButton;
@property (nonatomic, strong) UIView *splitView;
@property (nonatomic, strong) UIButton *nextUserNameButton;
@property (nonatomic, strong) UIButton *nextPasswordButton;
@property (nonatomic, strong) UITextField *userNameTextField;
@property (nonatomic, strong) UITextField *passwordTextField;
@end

@implementation TZLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationItem setTitle:@"用户登录"];
    [self.view endEditing:YES];
    [self setupUI];
}

//跟新UI
- (void)setupUI {
    [self addLogoInController];
    [self addPhoneNumberInController];
    [self addPassWordInController];
    [self addSMSButtonInController];
    [self addLoginButtonInController];
    [self addNewUserNameInController];
    [self addSplitLineInController];
    [self addNewPasswordInController];
}

//logo
- (void)addLogoInController {
    self.logoImageView = [[UIImageView alloc] init];
    [self.view addSubview:self.logoImageView];
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.view.mas_top).offset(20);
        make.width.mas_equalTo(KSCREEN_WIDTH * 0.8);
        make.height.mas_equalTo(self.logoImageView.mas_width).multipliedBy(0.5);
    }];
    self.logoImageView.image = [UIImage imageNamed:@"LoginScreen"];
}

//手机号
- (void)addPhoneNumberInController {
    self.userNameView = [[UIView alloc] init];
    [self.view addSubview:self.userNameView];
    [self.userNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.logoImageView.mas_bottom).offset(30);
        make.centerX.equalTo(self.logoImageView.mas_centerX);
        make.width.mas_equalTo(self.logoImageView.mas_width);
        make.height.mas_equalTo(40);
    }];
    //内嵌整体图片
    UIImageView *wholeImageView = [[UIImageView alloc] init];
    [self.userNameView addSubview:wholeImageView];
    [wholeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.userNameView);
    }];
    wholeImageView.image = [UIImage imageNamed:@"yuan"];
    //内嵌手机图片
    UIImageView *thumbnailImageView = [[UIImageView alloc] init];
    [wholeImageView addSubview:thumbnailImageView];
    [thumbnailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(wholeImageView.mas_left).offset(11);
        make.height.mas_equalTo(18.5);
        make.width.mas_equalTo(18);
        make.centerY.equalTo(wholeImageView.mas_centerY);
    }];
    thumbnailImageView.image = [UIImage imageNamed:@"shouji"];
    //内嵌textField
    UITextField *field = [[UITextField alloc] init];
    [self.userNameView addSubview:field];
    [field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(thumbnailImageView.mas_right).offset(7);
        make.right.equalTo(wholeImageView.mas_right).offset(-8);
        make.centerY.equalTo(wholeImageView.mas_centerY);
        make.height.mas_equalTo(thumbnailImageView.mas_height);
    }];
    field.placeholder = @"请输入手机号码";
    field.font = [UIFont systemFontOfSize:12.0];
    field.textColor = [UIColor blackColor];
    field.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.passwordTextField = field;
}

//密码
- (void)addPassWordInController {
    self.passWordView = [[UIView alloc] init];
    [self.view addSubview:self.passWordView];
    [self.passWordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userNameView.mas_bottom).offset(18);
        make.centerX.equalTo(self.logoImageView.mas_centerX);
        make.width.mas_equalTo(self.logoImageView.mas_width);
        make.height.mas_equalTo(40);
    }];
//    [self.passWordView startWithUIView:self.passWordView addWholeImage:@"yuan" addThumbnailImage:@"mima" addFieleString:@"请输入密码" addField:self.passwordTextField];
    //内嵌整体图片
    UIImageView *wholeImageView = [[UIImageView alloc] init];
    [self.passWordView addSubview:wholeImageView];
    [wholeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.passWordView);
    }];
    wholeImageView.image = [UIImage imageNamed:@"yuan"];
    //内嵌手机图片
    UIImageView *thumbnailImageView = [[UIImageView alloc] init];
    [wholeImageView addSubview:thumbnailImageView];
    [thumbnailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(wholeImageView.mas_left).offset(11);
        make.height.mas_equalTo(18.5);
        make.width.mas_equalTo(18);
        make.centerY.equalTo(wholeImageView.mas_centerY);
    }];
    thumbnailImageView.image = [UIImage imageNamed:@"mima"];
    //内嵌textField
    UITextField *field = [[UITextField alloc] init];
    [self.passWordView addSubview:field];
    [field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(thumbnailImageView.mas_right).offset(7);
        make.right.equalTo(wholeImageView.mas_right).offset(-8);
        make.centerY.equalTo(wholeImageView.mas_centerY);
        make.height.mas_equalTo(thumbnailImageView.mas_height);
    }];
    field.placeholder = @"请输入手机密码";
    field.font = [UIFont systemFontOfSize:12.0];
    field.textColor = [UIColor blackColor];
    field.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.passwordTextField = field;
}

//短信登录按钮
- (void)addSMSButtonInController {
    self.smsButton = [[UIButton alloc] init];
    [self.view addSubview:self.smsButton];
    [self.smsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passWordView.mas_bottom).offset(8);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(130);
        make.height.mas_equalTo(20);
    }];
    [self.smsButton setTitle:@"通过短信验证码登录" forState:UIControlStateNormal];
    [self.smsButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.smsButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [self.smsButton addTarget:self action:@selector(smsButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
}

//短信验证码登录的监听事件
- (void)smsButtonDidClick {
    TZSMSLoginController *smsLoginController = [[TZSMSLoginController alloc] init];
    [self.navigationController pushViewController:smsLoginController animated:YES];
}

//登录
- (void)addLoginButtonInController {
    self.loginButton = [[UIButton alloc] init];
    [self.view addSubview:self.loginButton];
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.smsButton.mas_bottom).offset(8);
        make.centerX.equalTo(self.logoImageView.mas_centerX);
        make.width.mas_equalTo(self.logoImageView.mas_width);
        make.height.mas_equalTo(35);
    }];
    [self.loginButton setBackgroundImage:[UIImage imageNamed:@"RedButton"] forState:UIControlStateNormal];
    [self.loginButton setBackgroundImage:[UIImage imageNamed:@"RedButtonPressed"] forState:UIControlStateHighlighted];
    [self.loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    [self.loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.loginButton addTarget:self action:@selector(loginButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
}

//登录按钮的监听事件
- (void)loginButtonDidClick {
    TZSuccessLoginController *successLoginController = [[TZSuccessLoginController alloc] init];
    [self.navigationController pushViewController:successLoginController animated:YES];
}

//注册新账号
- (void)addNewUserNameInController {
    self.nextUserNameButton = [[UIButton alloc] init];
    [self.view addSubview:self.nextUserNameButton];
    [self.nextUserNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.loginButton.mas_bottom).offset(20);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
        make.right.equalTo(self.view.mas_centerX).offset(-20);
    }];
    [self.nextUserNameButton setTitle:@"注册新账号" forState:UIControlStateNormal];
    [self.nextUserNameButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.nextUserNameButton.titleLabel.font = [UIFont systemFontOfSize:12.0];
    [self.nextUserNameButton addTarget:self action:@selector(nextUserNameButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
}

//注册新账号的监听事件
- (void)nextUserNameButtonDidClick {
    TZNewUserController *newUserController = [[TZNewUserController alloc] init];
    [self.navigationController pushViewController:newUserController animated:YES];
}

//分割线
- (void)addSplitLineInController {
    self.splitView = [[UIView alloc] init];
    [self.view addSubview:self.splitView];
    [self.splitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nextUserNameButton.mas_centerY);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(0.5);
        make.height.mas_equalTo(15);
    }];
    self.splitView.backgroundColor = [UIColor redColor];
}

//忘记密码
- (void)addNewPasswordInController {
    self.nextPasswordButton = [[UIButton alloc] init];
    [self.view addSubview:self.nextPasswordButton];
    [self.nextPasswordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.loginButton.mas_bottom).offset(20);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
        make.left.equalTo(self.view.mas_centerX).offset(20);
    }];
    [self.nextPasswordButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [self.nextPasswordButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.nextPasswordButton.titleLabel.font = [UIFont systemFontOfSize:12.0];
    [self.nextPasswordButton addTarget:self action:@selector(nextPasswordButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
}

//忘记密码的监听事件
- (void)nextPasswordButtonDidClick {
    TZNewPasswordController *newPasswordController = [[TZNewPasswordController alloc] init];
    [self.navigationController pushViewController:newPasswordController animated:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
@end
